import pymysql
# conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='zl122100!E', database='calender', charset='utf8')
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='root', database='calender', charset='utf8')
cur = conn.cursor()
sql="select * from normal "
# sql = "insert into normal(id,this_year,this_month,this_day,color,start_time,end_time,is_all_day,title,details) VALUES \
#     (111,'2022','12','21','green','12:00','17:05',False,'晨曦','fytfug'),\
#     (121,'2022','11','21','blue','11:00','17:23',False,'chenchen','vytuy') ;  "

cur.execute(sql)
conn.commit()
test1 = cur.fetchall()
year1 = {}
# month1 = {}
# day1 = {}

for i in test1:
    task = {}
    task["id"]=i[0]
    task["color"]=i[4]
    task["start_time"]=i[5]
    task["end_time"]=i[6]
    if i[7]==0:
        task["is_all_day"]=False
    else:
        task["is_all_day"]=True
    task["title"]=i[8]
    task["details"]=i[9]
    if year1.__contains__(i[1]):
        pass
    else:
        year1[i[1]]={}
    if year1[i[1]].__contains__(i[2]):
        pass
    else:
        year1[i[1]][i[2]]={}
    if year1[i[1]][i[2]].__contains__(i[3]):
        year1[i[1]][i[2]][i[3]].append(task)
    else:
        year1[i[1]][i[2]][i[3]]=[]
        year1[i[1]][i[2]][i[3]].append(task)

    year1[i[1]][i[2]]=year1[i[1]][i[2]]
    # year1[i[1]]=year1[i[1]]

    
       

print (year1)